<template>
  <div class="app-container">
    <div style="text-align: center;padding: 10px">安全预警详情信息</div>
    <div style="margin: 10px auto;text-align: center">
      <el-button type="primary" size="mini" v-if="this.warningForm.handleStatus=='01' && this.enterPriseHidden"
                 @click="assignPeople()"
                 align="center">分配人员
      </el-button>
      <el-button type="primary" size="mini" v-if="this.warningForm.handleStatus=='01' && this.enterPriseHidden"
                 @click="wrongReport()"
                 align="center">误 报
      </el-button>
<!--      <el-button type="primary" size="mini" v-if="!this.warningForm.checkStatus && this.enterPriseHidden1"-->
<!--                 @click="checkOpen"-->
<!--                 align="center">审 核-->
<!--      </el-button>-->
      <div style="width: 100%" v-if="show">
        <el-form :model="warningForm" ref="executePersonForm"
                 label-width="150px">
          <el-form-item label="执行人员" prop="handlePerson">
            <el-select v-model="warningForm.handlePerson" filterable placeholder="请选择执行人员"
                       style="width: 100%">
              <el-option v-for="(item,index) in userList" :key="index" :value="item.ucId"
                         :label="item.name"></el-option>
            </el-select>
          </el-form-item>
          <div align="center">
            <el-button type="primary" @click="updateData">确定</el-button>
          </div>
        </el-form>
      </div>
      <el-dialog title="审核" :visible.sync="show1" width="500px" append-to-body>
        <el-form :model="checkForm" ref="checkForm" label-width="80px">
<!--          <el-form-item label="审核结果" prop="checkContent">-->
<!--            <el-select v-model="checkForm.checkContent" filterable placeholder="请选择审核结果">-->
<!--              <el-option v-for="(item,index) in userList" :key="index" :value="item.ucId"-->
<!--                         :label="item.name"></el-option>-->
<!--            </el-select>-->
<!--          </el-form-item>-->
          <el-form-item label="审核结果" prop="checkContent">
            <el-input type="textarea" :autosize="{ minRows: 2}" v-model="checkForm.checkContent" placeholder="请输入审核结果"/>
          </el-form-item>
          <div align="center">
            <el-button type="primary" @click="checkConfirm">确定</el-button>
          </div>
        </el-form>
      </el-dialog>
    </div>
    <el-row :gutter="10">
      <el-form :model="warningForm" ref="warningForm" label-width="150px">
        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="安全预警标题:" prop="title">
              {{ warningForm.title }}
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="所属企业:" prop="enterpriseName">
              {{ warningForm.enterpriseName }}
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="上报时间:" prop="reportTime">
              {{ warningForm.reportTime | dateFormat }}
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="所属区域:" prop="regionName">
              {{ warningForm.regionName }}
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="处理人:" prop="handlePerson">
              {{ warningForm.handlePersonName }}
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="处理时间:" prop="reportTime">
              {{ warningForm.handleTime | dateFormat }}
            </el-form-item>
          </el-col>
          <el-col :xs="24" v-if="warningForm.checkStatus" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="审核结果:" prop="checkContent">
              {{ warningForm.checkContent }}
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="warningForm.imageUrl">
            <el-form-item label="预警图片:" prop="reportTime">
              <el-image :src="warningForm.imageUrl" style="width: 600px;"
                        fit="fill" :preview-src-list="[warningForm.imageUrl]">
                <div slot="placeholder" class="image-slot">
                  加载中<span class="dot">...</span>
                </div>
              </el-image>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="warningForm.handleResult">
            <el-form-item label="处理结果:" v-if="warningForm.handleResult==='00'">
              误报
            </el-form-item>
            <el-form-item label="处理结果:" v-else>
              <el-image :src="warningForm.handleResult" style="width: 150px; height: 250px;"
                        fit="fill" :preview-src-list="[warningForm.handleResult]">
                <div slot="placeholder" class="image-slot">
                  加载中<span class="dot">...</span>
                </div>
              </el-image>
            </el-form-item>
          </el-col>
        </el-col>
      </el-form>
    </el-row>
    <div slot="footer" style="text-align: center" class="dialog-footer">
      <el-button @click="cancelData">取 消</el-button>
    </div>
  </div>
</template>

<script>
import {getData, distribution, wrongReport,checkConfirm} from "@/api/warning";
import {getToken} from "@/utils/auth";
import {getInUserList, getRegionList} from "@/api/enterprise";

export default {
  name: "dataEdit",
  components: {},
  data() {
    return {
      show: false,
      warningForm: {
        name: "",
        regionId: "",
        code: "",
        ip: ""
      },
      addLoading: false,
      userList: [],
      regionList: [],
      ucId : this.$route.params.ucId,
      show1: false,
      checkForm:{
        checkContent:null
      }
    }
  },
  computed: {
    createStatus() {
      return this.$route.params.ucId == '0'
    },
    enterPriseHidden() {
      let roleCode = this.$store.getters.roleCode;
      return roleCode == "XZ-ADMIN"
    },
    enterPriseHidden1() {
      let roleCode = this.$store.getters.roleCode;
      return roleCode == "ADMIN" || roleCode == "XT-ADMIN" || roleCode == "ZD-ADMIN" || roleCode == "DD-ADMIN"
    },
    headers() {
      return {
        'Authorization': getToken()
      }
    }
  },
  created() {
    let ucId = this.$route.params.ucId
    this.getData(ucId)
  },
  methods: {
    checkOpen(){
      this.resetForm('checkForm')
      this.show1=true
    },
    checkConfirm(){
      this.checkForm.ucId=this.ucId
      checkConfirm(this.checkForm).then(res => {
        this.$notify.success({
          title: '成功',
          message: "审核完成"
        })
        this.cancelData()
      })
    },
    assignPeople() {
      this.show = true
    },
    wrongReport() {
      wrongReport({ucId:this.ucId}).then(res => {
        this.$notify.success({
          title: '成功',
          message: "处理完成"
        })
        this.cancelData()
      })
    },
    getInUserList(val) {
      getInUserList({deleted: false, flagId: val}).then(res => {
        this.userList = res.data
      }).catch(error => {

      })
    },
    getRegionList() {
      getRegionList({}).then(res => {
        this.regionList = res.data

      })
    },
    getData(val) {
      getData({ucId: val}).then(res => {
        this.warningForm = res.data
        this.getInUserList(res.data.enterpriseId)
      }).catch(res => {

      })
    },
    updateData() {
      this.addLoading = true
      this.$refs['warningForm'].validate(valid => {
        if (valid) {
          distribution(this.warningForm).then(res => {
            this.addLoading = false
            this.$notify.success({
              title: '成功',
              message: "分配执行人员成功"
            })
            this.cancelData()
          }).catch(res => {
            this.addLoading = false
            this.$notify.error({
              title: '失败',
              message: res.msg
            })
          })
        } else {
          this.addLoading = false
          console.log("表单验证不通过")
        }
      })
    },
    cancelData() {
      window.history.back()
    }
  }
}
</script>

